/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

 /***************************************************************************
  * Name: com_types.h
  *
  * Purpose: base types for 'COM' Functional
  *
  * Developer:
  *   wen.gu , 2020-06-12
  *
  * TODO:
  *
  ***************************************************************************/

  /******************************************************************************
   **    INCLUDES
   ******************************************************************************/
#ifndef __PANDA_COM_COM_TYPES_H__
#define __PANDA_COM_COM_TYPES_H__
#include <memory>
#include <functional>

#include "panda/core/types.h"
#include "panda/core/errors.h"
#include "panda/core/json.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/
#ifdef __cplusplus
#define COM_EXTERN_C extern "C"
#else
#define COM_EXTERN_C 
#endif


#if defined(_MSC_VER) /** !!!for visual studio */
    ////////////////////////////////////////////////////////////////////////////
    /** compat the keyword 'inline' */
#if (_MSC_VER > 1200) && !defined (__cplusplus)
#define inline    _inline  /** to compat keyword 'inline' */
#endif

#if defined (COM_DLL_EXPORT)
#define COM_API_EXPORT __declspec(dllexport)
#else
#define COM_API_EXPORT

#endif
#else /** for other toolchain */
#define COM_API_EXPORT 
#endif

    /** general api decorate macro */
#define COM_API COM_API_EXPORT /**c++ api */

#define COM_API_C COM_EXTERN_C COM_API_EXPORT /** c api */

/** general class decorate macro*/
#define COM_CLASS COM_API_EXPORT

/** general global variable decorate macro(for external reference ) */
#define COM_VAR  extern COM_API_EXPORT 

/** general const global variable decorate macro(for external reference ) */
#define COM_CVAR COM_VAR const 



 // Conditional NORETURN attribute on the throw functions would:
 // a) suppress false positives from static code analysis
 // b) possibly improve optimization opportunities.
#if !defined(COM_NO_RETURN)
#if defined(_MSC_VER)
#define COM_NO_RETURN __declspec(noreturn)
#elif defined(__GNUC__)
#define COM_NO_RETURN __attribute__((__noreturn__))
#else
#define COM_NO_RETURN
#endif
#endif

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
 /** request wait forever (for client do request)*/
#define COM_REQ_WAIT_INFINITE (-1)

/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
namespace panda
{
namespace com 
{

/** the mode of service work on */
enum class ServiceWorkMode : uint8_t
{
    kLocalOnly = 0, /** find(or get) service only on current system or machine side */
    kRemoteOnly = 1, /** find(or get) service only on remote side */
    kBoth = 2,  /** find(or get) service both on current system(or machine) and remote side
                 *  if have same service name, then return local sytem service at first.
                 */

};


/** for client side */
/**for request async ,
 * parameter: [1]: method Name, [2]: response information data */
using ClientReplyHandler = std::function<void(const std::string&, const panda::core::Value&)>;

/** for process signal,
 * paramter: [1]: signal name, [2]: signal content */
using ClientSignalHandler = std::function<void(const std::string&, const panda::core::Value&)>;


/** for service side */
/** request handle, indicat who send the request */
class ServiceRequestHandle;

using ServiceRequestHandlePtr = std::shared_ptr<ServiceRequestHandle>;
/**
 * ServiceRequestHandlePtr [in] who request the service to do method.
 * const std::string& [in] method name
 * panda::core::Value [in] request parameter data with json format
 */

using ServiceMethodHandler = std::function<void(ServiceRequestHandlePtr, const std::string&, const panda::core::Value&)>;


/******************************************************************************
**    CLASSES/FUNCTIONS DEFINITIONS
******************************************************************************/

} /** namespace com */
} /** namespace panda */


#endif /** !__PANDA_COM_COM_TYPES_H__ */